using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AutoGear.BLL;

public partial class admin_state_tax_add : SiteAdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        uccResponseMessage.Visible = false;
        if (!Page.IsPostBack)
        {
            uccState.DataBind();
        }
    }
    protected void Create_Click(object sender, EventArgs e)
    {
        try
        {
            Page.Validate();
            if (Page.IsValid)
            {
                string stateName = uccState.SelectedItem.Text;
                if (StateTax.GetBackendStateTaxListByStateNameCount(stateName, false) == 0)
                {
                    string stateCode = uccState.SelectedItem.Value;
                    double Tax;
                    double.TryParse(tbxTax.Text.Trim(), out Tax);
                    StateTax stateTax = new StateTax(0, stateName, stateCode, Tax, cbxIsActive.Checked, false, DateTime.Now);
                    stateTax.Create();
                    uccResponseMessage.Visible = true;
                    uccResponseMessage.SetSuccessMessage(AutoGearCommonMessage.StateTaxCreateSuccessful);
                    ClearControls();
                }
                else {
                    uccResponseMessage.SetFailMessage( AutoGearCommonMessage.StateTaxDuplicateStateCreate);
                    uccResponseMessage.Visible = true;
                }
            }
        }
        catch
        {
            uccResponseMessage.SetFailMessage(AutoGearCommonMessage.StateTaxCreateFailed);
            uccResponseMessage.Visible = true;
        }
    }

    private void ClearControls()
    {
        tbxTax.Text = "";
        uccState.SelectedIndex = 0;
        cbxIsActive.Checked = false;
    }
}


